package com.epfresh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.api.helper.ApplicationHelper;
import com.epfresh.api.widget.MsgView;
import com.epfresh.api.widget.tablayout.utils.UnreadMsgUtils;
import com.epfresh.global.BaseActivity;
import com.epfresh.global.DataManager;

public class HomeSecondAreaActivity extends BaseActivity implements DataManager.OnCartCountChangeListener{
    //购物车数量
    MsgView msgCount;
    //购物车图标
    ImageView ivCart;
    ImageView ivBack;
    public String seckillStoreId;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_second_area);
        TextView tv_title = (TextView)findViewById(R.id.tv_title);
        tv_title.setText("限时特价");
        msgCount = (MsgView) findViewById(R.id.msg);
        ivCart = (ImageView) findViewById(R.id.iv_cart);
        ivCart.setOnClickListener(this);
        ivBack = (ImageView) findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);
        DataManager.getInstance().registerMsgView("HomeSecondAreaActivity",this);
        DataManager.getInstance().updateCartCnt();
        seckillStoreId = getIntent().getStringExtra("seckillStoreId");
//        updateCount(DataManager.getInstance().getCartCnt());
    }
    protected View getToolBar() {

        return null;
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_cart:
                cart();

                break;
        }
    }

    public void cart() {
        if (ApplicationHelper.getInstance().getUser().getAccess_token() == null || "".equals(ApplicationHelper.getInstance().getUser().getAccess_token())) {
            Intent intent = new Intent(this, LoginActivity.class);
            intent.putExtra("relogin", true);
            startActivity(intent);
            return;
        }
        Intent intent = new Intent(this, HomeActivity.class);
        intent.putExtra("home_tab_index", 1);
        startActivity(intent);
        finish();
    }

    public void updateCount(int count) {

    }

    @Override
    public void onCartCountChange(int count) {
        UnreadMsgUtils.showLitter(msgCount, count, false);
        msgCount.setVisibility(View.VISIBLE);
    }
}